<template>
	<view class="uni-examtype">
		<view class="uni-flex-note" >
			<view class="uni-flex-title" v-if="!isEmpty(list)">
				{{list.title}}
			</view>
		</view>
		<view class="uni-exam-main">
			<view class="alone-title" v-if="list.itemType == 1">
				<text class="title">单选题</text>
				<text class="titleNum">
					<text class="no">{{list.currentcount}}</text>/{{list.sumcount}}
				</text>
			</view>
			
			<view class="alone-title" v-if="list.itemType == 2">
				<text class="title">多选题</text>
				<text class="titleNum">
					<text class="no">{{list.currentcount}}</text>/{{list.sumcount}}
				</text>
			</view>
			
			<view class="alone-title" v-if="list.itemType == 4">
				<text class="title">判断题</text>
				<text class="titleNum">
					<text class="no">{{list.currentcount}}</text>/{{list.sumcount}}
				</text>
			</view>
			
			<view class="type-alone">
				<type-alone v-if="!isEmpty(list.lantern) && status == 0 " :list="list.lantern" @isChoose="isChoose"></type-alone>
				<!-- <type-more v-if="!isEmpty(list.lantern) && status == 1 " :list="list.lantern" ></type-more> -->
			</view>
			<!-- <type-alone v-if="status == 0" :list="list"></type-alone>
			<type-more v-else-if="status == 1" :list="list"></type-more> -->
		</view>
		<view class="view-btn">
			<button type="default" @click="doup" size="mini" class="upbtn" :style="{'visibility':list.prevId>0?'visible':'hidden'}">上一题</button>
			<button type="default" @click="donext" size="mini" class="nextbtn" :style="{'background':choosetypevalue==1?'#FECA74':'#C3C3C3'}" v-if="list.nextId>0">下一题</button>
			<button type="default" @click="dofinish" size="mini" class="nextbtn" :style="{'background':choosetypevalue==1?'#FECA74':'#C3C3C3'}" v-if="list.nextId==0">完成</button><!-- 这种写法只有h5平台支持，不跨端，不推荐使用 -->
		</view>
	</view>
</template>

<script>
	import typeAlone from "./type-alone.vue"
	const util = require('@/common/util.js')
	export default {
		components:{
			typeAlone
		},
		props: {
			list:{
				type:Object,
				default:{}
			},
			status:{
				type:Number,
				default:0 //0:为单选；1：为多选
			},
			chooseType:{
				type:Number,
				default:0
			}
		},
		data() {
			return {
				timer: null,
				choosetypevalue:0 //0:未选 1：已选
				//chooseType: 0 //0：不可选 1：可选
			}
		},
		watch: {
			chooseType:function(val,oldval){
				//console.log(val+""+oldval)
				this.choosetypevalue = val
			}
		},
		created: function(e) {
			// console.log(this.chooseType)
			// this.choosetypevalue = this.chooseType
		},
		beforeDestroy() {
			
		},
		methods: {
			isEmpty(value){
				return util.isEmpty(value);
			},
			doup(){
				//console.log("doup")
				this.$emit('doUp',this.list.prevId)
			},
			donext(){
				//console.log("donext")
				if(this.choosetypevalue==0){
					uni.showToast({
						icon:'none',
					    title: '请先选择本题答案，在进入下一题',
					    duration: 2000
					});
				}else{
					this.$emit('doNext',this.list.nextId)
				}
			},
			dofinish(){
				//console.log(this.list.lantern)
				if(!util.isEmpty(this.list.lantern)){
					if(this.list.lantern.status==1){
						uni.showToast({
							icon:'none',
						    title: '您已完成答卷，认真检查后可点击下方“交卷”按钮，完成此次考试。',
						    duration: 2000
						});
					}else{
						if(this.choosetypevalue==0){
							uni.showToast({
								icon:'none',
							    title: '请先选择您的答案，在进行此操作',
							    duration: 2000
							});
						}else{
							this.$emit('doNext',this.list.nextId)
						}
					}
				}
			},
			isChoose(e){
				let that = this
				//console.log(JSON.stringify(e))
				let chooseStatus = false
				e.forEach((item,index) => {
					if(item.userAnswer==1){
						chooseStatus = true
					}
					//console.log(JSON.stringify(item))
				})
				if(chooseStatus){
					that.choosetypevalue = 1
				}else{
					that.choosetypevalue = 0
				}
				that.$emit('isChoose',e)
			}
		}
	}

</script>

<style lang="scss">
	.uni-exam-main{
		background: #FFFFFF;
		border-radius: 10upx;
		margin-top:20upx;
		padding-bottom:20upx;
		
		.alone-title{
			display: flex;
			justify-content: space-between;
			padding: 20upx;
			
			.title{
				color: rgb(32, 163, 245);
				
			}
			.titleNum{
				.no{
					color: rgb(32, 163, 245);
				}
			}
		}
		
	}
	.view-btn{
		display: flex;
		width: 100%;
		margin-top:50upx;
		align-items: center;
		justify-content: space-between;
		
		.upbtn{
			display: flex;
			width:230upx;
			height:70upx;
			line-height: 70upx;
			border-radius: 50upx;
			border: 1upx solid #ffffff;
			background: transparent;
			color: white;
			justify-content: center;
			align-items: center;
		}
		.nextbtn{
			display: flex;
			width:230upx;
			height:70upx;
			line-height: 70upx;
			border-radius: 50upx;
			background: rgb(195, 195, 195);
			color: white;
			justify-content: center;
			align-items: center;
		}
	}
	.uni-flex-title{
		color: white;
	}
	.line{
		clear: both;
		height:2upx;
		width: 100%;
		background: rgb(150,150,150);
	}
</style>
